package com.zed.api.games.answer.show;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import java.util.Random;

/**
 * 可选择的答案
 *
 * @author Zed
 */
public class AlternativeAnswer implements Serializable {

    @Serial
    private static final long serialVersionUID = -3802535303863633485L;
    private String id;
    private String text;

    /**
     * 用于序列化
     */
    protected AlternativeAnswer() {

    }

    public AlternativeAnswer(String id, String text) {
        this.id = Objects.requireNonNull(id, "\"id\" cannot be null.");
        this.text = Objects.requireNonNull(text, "\"text\" cannot be null.");
    }

    /**
     * 基于Id比较答案
     *
     * @param id {@link String},题目ID
     * @return {@link boolean},如果id相等则返回true,否则false
     */
    public boolean isBaseOnIdCompareAnswers(String id) {
        return Objects.equals(this.id, id);
    }

    /**
     * 获取答案唯一Id
     *
     * @return {@link String}
     */
    public String getId() {
        return this.id;
    }

    /**
     * 随机序号生成器
     *
     * @return {@link int}
     */
    public int getRandomIndex() {
        return new Random().nextInt(1, 10);
    }


    /**
     * 所显示的文本信息
     *
     * @return {@link String}
     */
    public String getText() {
        return this.text;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AlternativeAnswer that = (AlternativeAnswer) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

}
